<?php
/**
 * 	合同管理模板
 *  author： chengda
 *  date  ： 2017-11-22
 */
namespace Admin\Controller;

class ProjectInOutController extends AbstractController  {

	protected $From;

	public function _initialize(){
		$this->Form = D('projectinout');
    }
	

    public function index(){
	    $res = $this->Form->MyshowList();
		$this->assign("list",$res['list']);
    	$this->assign("page",$res['page']);
        $this->display();
    }
    //选择
    public function select(){
    	$res = $this->Form->Myselect();
		$this->assign("list",$res['list']);
    	$this->assign("page",$res['page']);
        $this->display();
    }

    public function save($type = false, $id = 0){

		$data['selectlist']['InOut']=$this->Form->InOutType();
		$Project=D('Project');
        $ProjectName=$Project->field("Name AS Name")->where(array('ID' =>I('ProjectID')))->find();
        $contract=D('contract');
        $ContractName=$contract->field("Title AS Name")->where(array('ID' =>I('ContractID')))->find();
        $result[0]['ProjectName']=$ProjectName['Name'];
        $result[0]['ContractName']=$ContractName['Name'];
        $result[0]['ProjectID']=I('ProjectID');
        $result[0]['ContractID']=I('ContractID');
       // return $result[0];
		$this->assign("data", $data);
		$this->assign("editdata",$result[0]);
		$this->display();
    }

    public function edit(){
    	if(I('ID')){
    		$data['selectlist']['InOut']=$this->Form->InOutType();
			$this->assign("data", $data);
			$res = $this->Form->Myshow((int)I('ID'));
			$this->assign("editdata",$res);
		}
		$this->display("save");
    }

    public function add(){
    	//var_dump($_POST); exit();
		$_POST['RecodTime']=date('Y-m-d H:i:s',time());
		$_POST['UserID']=session('USER_ID');
		//var_dump(session('USER_ID')); exit();
		if(!$this->Form->create()){

		exit($this->error($this->Form->getError()));
		}else{
		$result = $this->Form->add();
		if($result){
		$this->success('添加成功！');
		}else{
		$this->error('添加错误！');
		}
		}
		  
		
    }

    public function delete(){
    	$res = $this->Form->MydeletP();
    	if($res['state']){
			$this->success($res['msg']);
		}else{
			$this->error($res['msg']);
		}
    }

    public function update(){
		$result = $this->Form->Myupdata();
		//var_dump($result); exit();
		if($result['status'] == 1 && !empty($result)){
			$this->success($result['msg']);
		}else if($result['status'] == 0 && !empty($result)){
			$this->error($result['msg']);
		}
    }


   


}